package com.example.appointment.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.appointment.R;
import com.example.appointment.util.ToastUtil;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 手机登录的界面
 */
public class PhoneLoginActivity extends BaseActivity {
    @Bind(R.id.text1)
    TextView getcode;
    @Bind(R.id.activity_moblogin_phone)
    EditText phonenum;
    private TimeCounter timeCounter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setnotificationColore(R.color.maincolor);//設置导航栏顔色
        setContentView(R.layout.activity_phonelogin);
        initView();

    }

    /**
     *
     */
    private void initView() {
        setTitile("短信验证码登录");

    }

    /**
     * 下一步
     *
     * @param view
     */
    @OnClick(R.id.activity_phonelogin_next)
    public void next(View view) {
        startActivity(new Intent(PhoneLoginActivity.this, SetPwdActivity.class));
    }

    @OnClick(R.id.text1)
    public void next() {
        String phone = phonenum.getText().toString();
        timeCounter = new TimeCounter(60 * 1000, 1 * 1000);
        timeCounter.start();
        if (phone.length() != 11 || !phone.startsWith("1")) {
            ToastUtil.show(this, "请输入合法的手机号码");
            return;
        }
    }

    class TimeCounter extends CountDownTimer {

        public TimeCounter(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            long result = millisUntilFinished / 1000;
            getcode.setText(result + "秒后重发");
        }

        @Override
        public void onFinish() {
            getcode.setEnabled(true);
            getcode.setText("获取验证码");

        }
    }
}
